#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun May 20 19:12:41 2018
@project: 天池比赛-A股主板上市公司公告信息抽取
@group: 314寝室
@author: wangtao & wangjiang & lanhaiqiang
"""
import os
from functools import partial

import pandas as pd


def load_report(file_path, encoding='utf-8'):
    id_ = os.path.basename(file_path).split(".")[0]
    with open(file_path, encoding=encoding) as f:
        text = f.read()
    return id_, text


def load_reports(file_dir, encoding='utf-8'):
    for fname in os.listdir(file_dir):
        fpath = os.path.join(file_dir, fname)
        id_, text = load_report(fpath, encoding)
        yield id_, text
        
        
def load_train_data(file_path, columns):
    df = pd.read_table(file_path, names=columns)
    return df


zengjianchi_columns = ["report_id", "shareholder_fullname", "shareholder_shortname", "changed_date", "changed_price", "changed_quantity", "final_quantity", "final_percent"]
load_zengjianchi_train_data = partial(load_train_data, columns=zengjianchi_columns) 
